home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / frntsdk1.cpt / Frontier SDK 1.0 ƒ / Applet Toolkit / doscript.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-07  |  2.4 KB  |  86 lines

  1.  
  2.  
  3. /*⌐ Copyright 1988 -- 1991 UserLand Software, Inc.  All Rights Reserved.*/
  4.  
  5.  
  6. #include "appletinternal.h"
  7.  
  8.  
  9.  
  10.  
  11. boolean FrontierDoScript (bigstring script, bigstring returns) {
  12.     
  13.     /*
  14.     Send a Do Script message to Frontier. The first parameter contains a short
  15.     script to be run. The second parameter is the string that Frontier returned 
  16.     as the value generated by running the script. 
  17.     
  18.     Returns true if we were able to send the message to Frontier, and Frontier
  19.     was able to compile and run the script and Frontier replied with a returned
  20.     value. FrontierDoScript returns false if Frontier isn't running, or if the
  21.     script didn't compile or if there was a communications error.
  22.     
  23.     Frontier is not limited to running 255-character scripts or returning 
  24.     255-character returned values. This routine can easily be enhanced to handle 
  25.     larger scripts and returned values. 
  26.     
  27.     11/6/91 DW: Set return string to "IAC Error" if we failed to create an Apple
  28.     event descriptor or if the send failed. We're not suggesting that your
  29.     error messages should be so brief, rather they should be custom-fit to the
  30.     appropriate audience. Here, we want to show you how to locate errors relating
  31.     to the IAC channel -- either you're low on memory, or the Apple Event Manager
  32.     isn't present, or Frontier isn't running. Watch for this string in FDS's 
  33.     little window...
  34.     
  35.     11/7/91 DW: This code was cribbed from the Frontier Do-Script program and adapted
  36.     to run on top of the IAC Tools library. Use this version of FDS if you're using
  37.     the IAC Tools library, use the original version if you're writing code to run
  38.     directly on top of the Apple Event Manager.
  39.     */
  40.  
  41.     register Boolean flhavereply = false;
  42.     AppleEvent event, reply;
  43.     
  44.     copystring ("\pIAC Error.", returns); /*default return string*/
  45.     
  46.     if (!IACnewverb ('LAND', 'misc', 'dosc', &event))
  47.         return (false);
  48.     
  49.     IACglobals.event = &event;
  50.     
  51.     if (!IACpushstringparam (script, '----'))
  52.         return (false);
  53.         
  54.     if (!IACsendverb (&event, &reply))
  55.         goto error;
  56.     
  57.     flhavereply = true;
  58.     
  59.     IACglobals.reply = &reply;
  60.     
  61.     if (IACiserrorreply (returns)) /*syntax error or runtime error*/
  62.         goto error;
  63.         
  64.     IACglobals.event = &reply; /*get the string from the reply record*/
  65.         
  66.     if (!IACgetstringparam ('----', returns))
  67.         goto error;
  68.     
  69.     AEDisposeDesc (&event);    
  70.     
  71.     AEDisposeDesc (&reply);
  72.     
  73.     return (true);
  74.     
  75.     error:
  76.     
  77.     AEDisposeDesc (&event);    
  78.     
  79.     if (flhavereply)
  80.         AEDisposeDesc (&reply);
  81.     
  82.     return (false);
  83.     } /*FrontierDoScript*/
  84.     
  85.     
  86.